import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const state = {
	// 页面标题
	title: '发现',
	head: {
		backShow: false,
		focusShow: false
	},
	focusSelect: 'science',
	user: {
		name: '刁滑猾',
		introduction: '吱吱吱1',
		funs: ['101'],
		focus: ['101']
	},
	book: {
		favorite: ['101', '102', '303'],
		focus: ['science', 'workspace']
	},
	set: {
		like: false,
		comment: true,
		letter: false
	}
}

const mutations = {
	UPDATE_TITLE: function (state, title) {
		state.title = title
	},
	UPDATE_HEAD_BACKSHOW: function (state, value) {
		state.head.backShow = value
	},
	UPDATE_HEAD_FOCUSSHOW: function (state, value) {
		state.head.focusShow = value
	},
	UPDATE_FOCUS_SELECT: function (state, value) {
		state.focusSelect = value
	},
	UPDATE_USER_NAME: function (state, value) {
		state.user.name = value
	},
	UPDATE_USER_INTRODUCTION: function (state, value) {
		state.user.introduction = value
	},
	UPDATE_SET_LIKE: function (state, value) {
		state.set.like = value
	},
	UPDATE_SET_COMMENT: function (state, value) {
		state.set.comment = value
	},
	UPDATE_SET_LETTER: function (state, value) {
		state.set.letter = value
	},
	UPDATE_SET: function (state, key, value) {
		state.set[key] = value
	},
	UPDATE_BOOK: function (state, key, value) {
		let index = state.book[key].indexOf(value)
		if (index === -1) {
			state.book[key].push(value)
		} else {
			state.book[key].splice(index, 1)
		}
	}
}

export default new Vuex.Store({
	state,
	mutations
})
